// index.js goods相关接口
const express=require('express')
const mysql=require('mysql')
const goods=express.Router()
const database=require('../database')
const db=mysql.createPool(database)
goods.use(express.json())
goods.use(express.urlencoded({ extended: false}));
goods.use(express.static('./'))
goods.post('/list',(req,res)=>{
    let sql="select * from t_goods"
    db.query(sql,[],(err,list)=>{
        if(list){
            res.send({
                success:true,
                msg:'成功',
                list
            })
        }else{
            res.send({
                success:false,
                msg:'失败'
            })
        }
    })
})
goods.post('/getGoods',(req,res)=>{
    let sql="select * from t_goods where id=?"
    db.query(sql,[req.body.id],(err,goods)=>{
        if(goods.length){
            res.send({
                success:true,
                msg:'成功',
                goods:doods[0]
            })
        }else{
            res.send({
                success:false,
                msg:'失败'
            })
        }
    })
})
module.exports=goods